#!/bin/sh
#****************************************************************#
# ScriptName: createzone.sh
# Author: liujmsunits@hotmail.com
# Create Date: 2015-05-24 06:17
# Modify Author: liujmsunits@hotmail.com
# Modify Date: 2015-05-24 08:35
# Function: 
#***************************************************************#
for i in `cat host`
do
	domainid=(`cat zone2name |grep zjj |awk '{print $1}'`)
	cfgname=(`cat zone2name |grep zjj |awk '{print $2}'`)
	hostname=(`cat zone2name |grep zjj |awk '{print $3}'`)
	sunname=(`cat zone2name |grep zjj |awk '{print $4}'`)
	index=(`cat zone2name |grep zjj |awk '{print $5}'`)

function sel(){
eval "var1=\${$1[0]}"
eval "var2=\${$1[1]}"
eval "var3=\${$1[2]}"
eval "var4=\${$1[3]}"
#echo $var1
#echo $var2
#echo $var3
#echo $var4
}

function diff(){
	if [ $1 = $2 ]
	then
		return 0
	else
		return 1
	fi
}

function sameordiff(){
if [ $? = 0 ] ;then
	echo "same"
else
	echo "diff"
fi
}

function zonecreate(){
if [ $1 = host1 ]
then
	echo "
zonecreate \"$zonename1\",\"$domainid1,$index1;$domainid2,$index2\"
cfgadd \"$cfgname1\",\"$zonename1\"
cfgenable \"$cfgname1\""
elif [ $1 = host2 ]
then
	echo "
zonecreate \"$zonename2\",\"$domainid3,$index3;$domainid4,$index4\"
cfgadd \"$cfgname2\",\"$zonename2\"
cfgenable \"$cfgname2\""
else
	echo "pls use zonecreate host1/host2"
fi
}

#sel domainid
#diff $var1 $var2
#sameordiff
#sel cfgname
#diff $var1 $var2
#sameordiff
#sel hostname
#diff $var1 $var2
#sameordiff
#sel index
#diff $var1 $var2
#sameordiff
sel hostname
diff $var1 $var2
if [ $? = 0 ]
then
	hostname1=$var1
	hostname2=$var3
else
	echo "pls check the hostname"
fi

sel sunname
diff $var1 $var2
if [ $? = 0 ]
then
	sunname1=$var1
	sunname2=$var3
else
	echo "pls check the sunname"
fi

zonename1="$hostname1"_"$sunname1"
zonename2="$hostname2"_"$sunname2"

sel domainid 
domainid1=$var1
domainid2=$var2
domainid3=$var3
domainid4=$var4

sel index
index1=$var1
index2=$var2
index3=$var3
index4=$var4

sel cfgname
diff $var1 $var2
if [ $? = 0 ]
then
	cfgname1=$var1
	cfgname2=$var3
else
	cfgname1=$var1
	cfgname2=$var2
	cfgname3=$var3
	cfgname4=$var4
fi

zonecreate host1
zonecreate host2

done
